﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using DataAccess_Layer;
using System.Data;

namespace Business_Layer
{
    public static class Product_BUS
    {
        public static DataTable getProductsByCatID(int catID)
        {
            List<ProductWithCatNameDTO> result = new List<ProductWithCatNameDTO>();

            foreach (ProductWithCatNameDTO product in Product_DAC.getAllWithCatNameUpdate())
            {
                if (product.CatID== catID)
                {
                    result.Add(product);
                }
            }

            return result.ToDataTable<ProductWithCatNameDTO>();
        }
        public static DataTable getProductsByProdID(int catID)
        {
            List<ProductWithCatNameDTO> result = new List<ProductWithCatNameDTO>();

            foreach (ProductWithCatNameDTO product in Product_DAC.getAllWithCatName())
            {
                if (product.ID == catID)
                {
                    result.Add(product);
                }
            }

            return result.ToDataTable<ProductWithCatNameDTO>();
        }

        public static DataTable createProductForCart(int id, int orderedQuantity)
        {
            List<ProductWithCatNameDTO> result = new List<ProductWithCatNameDTO>();

            foreach (ProductWithCatNameDTO product in Product_DAC.getAllWithCatName())
            {
                if (product.ID == id)
                {
                    product.Total = orderedQuantity;
                    result.Add(product);
                    break;
                }
            }

            return result.ToDataTable<ProductWithCatNameDTO>();
        }
        public static DataTable createProductForUpdate(int id)
        {
            List<ProductWithCatNameDTO> result = new List<ProductWithCatNameDTO>();

            foreach (ProductWithCatNameDTO product in Product_DAC.getAllWithCatName())
            {
                if (product.ID == id)
                {
                   
                    result.Add(product);
                    break;
                }
            }

            return result.ToDataTable<ProductWithCatNameDTO>();
        }
        
        public static long insert(ProductDTO newProduct)
        {
            return Product_DAC.insert(newProduct);
        }

        public static bool update(ProductDTO updatedProd)
        {
            return Product_DAC.update(updatedProd);
        }
    }
}
